import {Modal, Button} from 'antd';
import {inject, observer} from "mobx-react";
import {toJS} from 'mobx';
import {
  WeaDialog,
  WeaLocaleProvider,
  WeaRightMenu
} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import * as blogUtil from '../../../util/index';

@inject('blogSetting')
@observer
export default class CreateModule extends React.Component {
  constructor(props){
    super(props);
    this.state={}
  }

  getRightMenu = () => {
    let btns = [
      {
        key: 'CREATE_SAVE',
        icon: <i className='icon-coms-Preservation'/>,
        content: getLabel(30986,"保存"),
        onClick: () => this.onRightMenuClick('BTN_SAVE')
      },
      {
        key: 'CREATE_SAVESET',
        icon: <i className = 'icon-coms-Flow-setting'/>,
        content:`${getLabel(32159,'保存并进入详细设置')}`,
        onClick: () => this.onRightMenuClick('BTN_SAVESET'),
      },
    ];
    return btns;
  }

  onRightMenuClick = (type) => {
    const {blogSetting} = this.props;
    const {moduleDialogForm} = blogSetting;
    const formParams = moduleDialogForm && moduleDialogForm.getFormParams();
    if(type == 'BTN_SAVE'){
      blogUtil.onCheck(moduleDialogForm, () => {
        blogSetting.operateBlogTemplateSet({operation: 'saveTemp', isSystem: 0, ...formParams}, 'create');
      })
    }
    if(type == 'BTN_SAVESET'){
      blogUtil.onCheck(moduleDialogForm, () => {
        blogSetting.operateBlogTemplateSet({operation: 'saveTemp', isSystem: 0, ...formParams}, 'createSet');
      })
    }
  }

  render() {
    const {blogSetting} = this.props;
    const {showCreate, moduleDialogFields, createLoading} = toJS(blogSetting.moduleStatus);
    const {isEcme} = this.props.blogSetting;
    const title = getLabel(28051, "新建模板");
    const collectParams={
      favname: title,
      favouritetype: 1,
      objid:0,
      link:'wui/engine.html#/blogengine/setting',
      importantlevel: 1,
    };


    let hh = isEcme == "1"?"200px":"146px";


    return (
      <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@lyuwrw`}
        title={title}
        icon="icon-coms-blog"
        iconBgcolor="#6d3cf7"
        className='wea-blog-module-dialog'
        style={{width: 700, height:hh}}
        visible={showCreate}
        buttons={[
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@gnx9ka@submit`} key="submit" type="primary" size="large" loading={createLoading} onClick={() => this.onRightMenuClick('BTN_SAVE')}>{getLabel(30986, "保存")}</Button>,
          <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@9dldf0@detsave`} type='primary' onClick={() => this.onRightMenuClick('BTN_SAVESET')}>{getLabel(32159,'保存并进入详细设置')}</Button>
        ]}
        moreBtn={{collectParams: collectParams}}
        onCancel={() => {
          blogSetting.setModuleState({showCreate: false});
          blogSetting.doModuleFormInit();
        }}
      >
        <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@olwxsp`}
          datas={this.getRightMenu()}
          collectParams={{collectParams}}
        >
          {blogUtil.getFormSearchs(blogSetting.moduleDialogForm, moduleDialogFields,false,false,false,this.props.ecId || '')}
        </WeaRightMenu>
      </WeaDialog>
    )
  }
}